<template>
	<view class="delivery">

		<view class="get_info">
			<view class="fc">
				<!-- <text class="iconfont iconwode11"></text> -->
				<view class="left">收货人</view>
				<view class="rights">
					<input type="text" v-model="form.shou_name" placeholder="请填写收货人姓名"
						placeholder-class="place_style" />
				</view>
			</view>

			<view class="fc">
				<view class="left"></view>
				<view class="rights">
					<u-radio-group active-color="#e34b0f" class="sex_box" v-model="form.sex">
						<u-radio class="radio" v-for="(item, index) in sexList" :key="index" :name="item.id">
							{{item.name}}
						</u-radio>
					</u-radio-group>
				</view>
			</view>


			<view class="fc">
				<view class="left">电话</view>
				<view class="rights">
					<input type="number" v-model="form.shou_phone" placeholder="请填写收货电话号码"
						placeholder-class="place_style" />
				</view>
			</view>

			<view class="fc" @click="toArea()">
				<view class="left">地址</view>
				<view class="rights fc">
					<text class="iconfont iconshouhuodizhi"></text>
					<input type="text" disabled v-model="form.address" placeholder="小区/写字楼/学校等"
						placeholder-class="place_style" />
					<text class="iconfont iconfanhui t-180"></text>
				</view>
			</view>

			<view class="fc">
				<view class="left">门牌号</view>
				<view class="rights">
					<input type="text" v-model="form.code" placeholder="例: 6栋1单元309号" placeholder-class="place_style" />
				</view>
			</view>
		</view>
		<view class="submit_button button_style" @click="submit">保存</view>
		<w-picker :visible.sync="visible" mode="linkage" :value="defaultRegion1" :options="option" :level="3"
			default-type="id" :default-props="defaultProps1" @confirm="confirmAddrss($event,'linkage')" ref="linkage">
		</w-picker>
	</view>
</template>

<script>
	import wPicker from "@/components/w-picker/w-picker.vue";
	export default {
		components: {
			wPicker
		},
		data() {
			return {
				visible: false,
				form: {
					shou_name: '',
					province: '',
					city: '',
					area: '',
					sex: '',
					shou_phone: '',
					address: '',
					code: '',
					lat: '',
					long: ''
				},
				is_check: false,
				receiving: '',
				defaultProps1: {
					label: "name",
					value: "id",
					children: "child"
				},
				defaultRegion1: [],
				option: [],
				sexList: [{
					id: 1,
					name: '先生'
				}, {
					id: 2,
					name: '女生'
				}],

			};
		},
		methods: {
			toArea(){
				let _=this;
				// 获取当前位置信息
			
				  
				    // 调起地图并显示指定的经纬度
				    uni.chooseLocation({
				       success(e) {
						  console.log(e);
				          _.form.address=e.address;
						  _.form.lat=e.latitude;
						  _.form.long=e.longitude;
				       },
					   fail(e) {
					   	console.log(e);
					   }
				    });
				  
			
			},
			setDefault(e) {
				this.is_check = e.detail.value;
			},
			mapPage() {
				this.visible = true;
			},
			submit() {
				let params = Object.assign({}, this.form)
				
				
				console.log(this.is_check)
				params.is_check = this.is_check ? 2 : 1;
				this.$post(this.$api.aEdit, params, (res) => {
					let {
						data
					} = res;
					if (data.code == 1) {
						this.$Toast('保存成功');
						setTimeout(() => {
							uni.navigateBack()
						}, 1000)
					} else {
						this.$Toast(data.msg);
					}
				})
			},
			getAddress() {
				this.$get(this.$api.mainRegion, {}, (res) => {
					let {
						data
					} = res;
					if (data.code == 1) {
						data.data.map((item) => {
							if (item.child.length == 0) {
								item.child = [{
									id: '',
									name: '',
									child: [{
										id: '',
										name: ''
									}]
								}]
							}
							item.child.map((second) => {
								if (second.child.length == 0) {
									second.child = [{
										id: '',
										name: ''
									}]
								}
							})
							return item;
						})
						this.option = data.data;
					}
				})
			},
			confirmAddrss(e) {
				this.receiving = e.result;
				this.form.province = e.obj.col1.name;
				this.form.city = e.obj.col2.name;
				this.form.area = e.obj.col3.name;
			}
		},
		onLoad(option) {
			console.log(option.item)
			this.form = JSON.parse(option.item);
			let {
				province,
				city,
				area
			} = this.form;
			delete this.form.updatetime;
			this.is_check = this.form.is_check == 1 ? false : true;
			this.receiving = province + city + area
			this.getAddress();
		},
	};
</script>

<style lang="scss" scoped>
	::v-deep .u-radio__label {
		margin-right: 100rpx !important;
		font-size: 28rpx !important;
	}

	.iconshouhuodizhi {
		color: #989898;
		font-size: 40rpx !important;
	}

	.iconfanhui {
		color: #9c9c9c;
		;
		font-size: 40rpx !important;
	}

	page {
		background-color: white;
	}

	.delivery .get_info {
		background: white;
		padding: 0 20rpx;
		// margin-top: 10rpx;
	}

	.delivery .get_info>view {
		display: flex;
		// height: 100rpx;
		//padding: 10rpx 0;
		align-items: center;

	}


	.delivery .get_info>view>text {
		width: 70rpx;
		// color: #808080;
	}

	.delivery .button_style {
		font-size: 30rpx;
		margin: 100rpx 30rpx 0;
		height: 75rpx;
		line-height: 75rpx;
		border-radius: 45rpx;
		background: #e34b0f;
	}

	.delivery input {
		padding: 0;
		width: 100%;
	}

	.delivery text-no-space {
		white-space: pre-line;
	}

	.delivery {
		.iconfont {
			font-size: 60rpx;
		}
	}

	.fc {
		display: flex;
		align-items: center;
	}

	.left {
		width: 16%;
		font-size: 28rpx;
	}

	.rights {
		width: 84%;
		box-sizing: border-box;
		padding: 25rpx 0;
		border-bottom: 1px solid #eee;
	}
</style>